#define fexit(s) { fprintf( stderr, "%s\n", s ); exit(1); }
#include <stdio.h>
#include <stdlib.h>
#include "../../jerasure-2.h"

int main( int argc, char** argv )
{
	JER_Matrix *matrix;
	int r = atoi( argv[1] );
	int c = atoi( argv[2] );
	int w = atoi( argv[3] );
	JER_Matrix *matrix2;
	int i, j, fsize;

	matrix = new JER_Matrix( r, c, w );
	matrix2 = new JER_Matrix( r, c, w );
	if( matrix == NULL )
		fexit( "Matrix could not be allocated." );
	srand48(c);
	fsize = 1 << w;
	for( i = 0; i < r * c; i++ )
	{
		matrix->Elts[i/c][i%c] = lrand48() % fsize;
		matrix2->Elts[i/c][i%c] = lrand48() % fsize;
	}
	for( i = r/2; i < r; i++ )
		for( j = c/2; j < c; j++ )
			matrix->Elts[i][j] ^= matrix2->Elts[i-r/2][j-c/2];
	matrix->Print();
	fprintf( stdout, "---------\n" );
	matrix2->Print();

	return 0;
}
